var mobId, mob, stats;
var 清怪 = true;
var 刷新地图 = true;
var 复活次数 = 11;
var 副本名称 = "组队任务_毒雾森林";
var BOSS_1_id = 9300182;
var BOSS_1_血量倍率 = 60;
var 副本时限 = 1000 * 60 * 40;
var 实例地图 = [930000000, 930000100, 930000200, 930000300, 930000400, 930000500, 930000600, 930000700, 930000800];
var 准备地图 = 300030010;
var 退场倒计时 = 40;

function init() {}

function setup(f, a) {
    em.getProperties().clear();
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    em.setProperty("spine_end", "0");
    em.setProperty("maze_end", "0");
    em.setProperty("purify_end", "0");
    em.setProperty("jump_end", "0");
    em.setProperty("BOSS_end", "0");
    em.setProperty("final_end", "0");
    var c = em.newInstance(副本名称);
    for (var b = 0; b < 实例地图.length; b++) {
        var e = c.setInstanceMap(实例地图[b]);
        e.resetPQ(f);
        e.resetFully();
        e.killAllMonsters(清怪);
        e.respawn(刷新地图);
        if (b == 5) {
            e.shuffleReactors()
        }
    }
    c.startEventTimer(副本时限);
    c.setProperty("FBtime", 副本时限);
    c.setProperty("FBname", 副本名称);
    c.setProperty("strMap", 准备地图);
    var d = em.getMonster(BOSS_1_id).getMobMaxHp() * BOSS_1_血量倍率;
    c.setProperty("BOSShp", d);
    return c
}

function onItemPickedUp(c, b, g) {
    var d = 0;
    var f = p.getMapId();
    if (f == 930000200) {
        d = 1
    } else {
        if (f == 930000400) {
            d = 20
        } else {
            if (f == 930000500) {
                d = 1
            }
        }
    }
    if (d > 0) {
        if (g == 4001161) {
            var e = 0;
            c.getPlayers().forEach(function (i) {
                e += i.getAPI().getItemQuantity(4001161)
            });
            var h = b.getAPI().getJobName(b.getAPI().getJob());
            var a = b.getName();
            c.getPlayers().forEach(function (i) {
                if (e >= d) {
                    i.getAPI().addPopupSay(2133000, 4000, "这是猛烈毒素，必须拿到泉水中净化。");
                    i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『变质的森林』找到" + (e) + "个猛烈毒素。", 3, 20, 13, 0)
                } else {
                    i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『变质的森林』找到" + (e) + "个猛烈毒素。", 3, 20, 13, 0)
                }
            })
        } else {
            if (g == 4001162) {
                var e = 0;
                c.getPlayers().forEach(function (i) {
                    e += i.getAPI().getItemQuantity(4001162)
                });
                var h = b.getAPI().getJobName(b.getAPI().getJob());
                var a = b.getName();
                c.getPlayers().forEach(function (i) {
                    if (e >= d) {
                        i.getAPI().addPopupSay(2133000, 4000, "毒素已经被稀释了，快去净化尖刺孢子。");
                        i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『变质的森林』找到" + (e) + "个稀释的毒素。", 3, 20, 13, 0)
                    } else {
                        i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『变质的森林』找到" + (e) + "个稀释的毒素。", 3, 20, 13, 0)
                    }
                })
            } else {
                if (g == 4001169) {
                    var e = 0;
                    c.getPlayers().forEach(function (i) {
                        e += i.getAPI().getItemQuantity(4001169)
                    });
                    var h = b.getAPI().getJobName(b.getAPI().getJob());
                    var a = b.getName();
                    c.getPlayers().forEach(function (i) {
                        if (e >= d) {
                            i.getAPI().addPopupSay(2133000, 4000, "已经很多了，快交给队长吧。");
                            i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『中毒的森林』找到" + (e) + "个怪物之珠，快交给队长吧。", 3, 20, 13, 0)
                        } else {
                            i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『中毒的森林』找到" + (e) + "个怪物之珠，快交给队长吧。", 3, 20, 13, 0)
                        }
                    })
                } else {
                    if (g == 4001163) {
                        var e = 0;
                        c.getPlayers().forEach(function (i) {
                            e += i.getAPI().getItemQuantity(4001163)
                        });
                        var h = b.getAPI().getJobName(b.getAPI().getJob());
                        var a = b.getName();
                        c.getPlayers().forEach(function (i) {
                            if (e >= d) {
                                i.getAPI().addPopupSay(2133000, 4000, "拿到了紫色魔力石，快交给队长吧。");
                                i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『森林空地』找到" + (e) + "个紫色魔力石，快交给队长吧。", 3, 20, 13, 0)
                            } else {
                                i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『森林空地』找到" + (e) + "个紫色魔力石，快交给队长吧。", 3, 20, 13, 0)
                            }
                        })
                    } else {
                        if (g == 4001164) {
                            var e = 0;
                            c.getPlayers().forEach(function (i) {
                                e += i.getAPI().getItemQuantity(4001164)
                            });
                            var h = b.getAPI().getJobName(b.getAPI().getJob());
                            var a = b.getName();
                            c.getPlayers().forEach(function (i) {
                                if (e >= d) {
                                    i.getAPI().addPopupSay(2133000, 4000, "拿到了紫色魔力石，快交给队长吧。");
                                    i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『毒树丛』找到" + (e) + "个石头人的毒珠，快交给队长吧。", 3, 20, 13, 0)
                                } else {
                                    i.getAPI().getTopMsgFont("" + h + "<" + a + ">在『毒树丛』找到" + (e) + "个石头人的毒珠，快交给队长吧。", 3, 20, 13, 0)
                                }
                            })
                        }
                    }
                }
            }
        }
    }
}

function WarpTask(b, a) {
    player.scheduleWarpTask(4, b, a, false)
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(实例地图[0]);
    a.dropMessage(6, "[" + 副本名称 + "] 进入到了挑战地图，请小心行事。");
    a.changeMap(c, c.getPortal(0));
    a.setReviveCount(复活次数);
    a.getAPI().setNumberForQuestInfo(准备地图, "damage", 0);
    a.tryPartyQuest(1206)
}

function onPlayerKilled(b, a) {}

function onPlayerRevived(b, a) {
    if (a.getReviveCount() > 0) {
        return true
    } else {
        var c = b.getMapFactoryMap(准备地图);
        a.changeMap(c, c.getPortal(0));
        return true
    }
}

function onMapChanged(d, c, b) {
    var a = 实例地图.indexOf(b);
    if (a < 0) {
        on玩家退场(d, c, false);
        return
    }
    switch (a) {
        case 0:
            break;
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;
        case 6:
            break;
        case 7:
            break;
        default:
            break
    }
}

function onMonsterKilled(b, c) {
    if (c == 9300182) {
        openNpc(b, 9130027, "评价系统");
        for (var a = 0; a < b.getPlayerCount(); a++) {
            b.getPlayers().get(a).dropMessage(6, "[" + 副本名称 + "] 成功击杀BOSS！")
        }
        em.setProperty("BOSS_end", "1")
    } else {
        var d = p.getMapId();
        if (d == 930000100) {
            if (player.getMap().getNumMonsters() == 0) {
                b.getPlayers().forEach(function (e) {
                    e.getAPI().fieldEffect_ScreenMsg("quest/party/clear");
                    e.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100)
                });
                player.getAPI().addPopupSay(2133000, 4000, "请快点移动到下一个地图！")
            } else {
                b.getPlayers().forEach(function (e) {
                    e.getAPI().playerMessage(-1, "怪物还剩" + e.getMap().getNumMonsters() + "个。")
                })
            }
        }
    }
    return 1
}

function onMonsterDamaged(b, a, d, e, c) {
    if (d == BOSS_1_id) {
        a.getAPI().addNumberForQuestInfo(准备地图, "damage", e)
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function initPropArrayRandom(a, d, j, b, h) {
    var g = new Array();
    var k = h - b + 1;
    var c = (j - d) < (h - b) ? true : false;
    do {
        var f = randomNum(d, j);
        if (c || g.indexOf(f) < 0) {
            g.push(f);
            k--
        }
    } while (k);
    for (var e = b; e <= h; e++) {
        if (em.getProperty(a + "_" + e) == null) {
            em.setProperty(a + "_" + e, g[e - 1])
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onPartyDisbanded(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, true);
    return 0
};